package cn.foxtech.cloud.repo.comp.script.entity;

import cn.craccd.mongoHelper.bean.BaseModel;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.index.Indexed;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * 脚本软件版本信息
 */
@Getter(value = AccessLevel.PUBLIC)
@Setter(value = AccessLevel.PUBLIC)
public class RepoCompScriptVersionEntity extends BaseModel {
    /**
     * 作者：主要是开发者
     */
    @Indexed
    private String author;

    /**
     * 父节点RepoCompScriptEntity的ID
     */
    @Indexed
    private String scriptId;
    /**
     * 版本描述
     */
    private String description;
    /**
     * 操作信息
     */
    private List<RepoCompScriptOperateEntity> operates = new ArrayList<>();

    public static String makeOperatesValue(List<RepoCompScriptOperateEntity> list) {
        list.sort(new Comparator<RepoCompScriptOperateEntity>() {
            @Override
            public int compare(RepoCompScriptOperateEntity v1, RepoCompScriptOperateEntity v2) {
                String name1 = v1.getOperateName();
                String name2 = v2.getOperateName();
                return name1.compareTo(name2);
            }
        });

        StringBuilder sb = new StringBuilder();
        for (RepoCompScriptOperateEntity entity : list) {
            sb.append(entity.makeServiceValue());
            sb.append(";");
        }

        return sb.toString();
    }
}
